import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

class PracticeTypeSelectionScreen extends StatefulWidget {
  const PracticeTypeSelectionScreen({super.key});

  @override
  State<PracticeTypeSelectionScreen> createState() => _PracticeTypeSelectionScreenState();
}

class _PracticeTypeSelectionScreenState extends State<PracticeTypeSelectionScreen> {

  // 已移除对话框方法，改为直接在卡片上显示按钮

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('题目练习', style: TextStyle(fontFamily: 'FangSong')),
        centerTitle: true,
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: ListView(
          children: [
            const SizedBox(height: 8),
            const Text(
              '选择题目类型',
              style: TextStyle(fontSize: 22, fontWeight: FontWeight.w600, fontFamily: 'FangSong'),
              textAlign: TextAlign.start,
            ),
            const SizedBox(height: 16),
            _buildPracticeTypeCard(
              context,
              title: '时政题目',
              description: '时事政治、党史知识等',
              icon: Icons.account_balance,
              color: Colors.blue,
              route: '/practice/questions/politics',
            ),
            const SizedBox(height: 10),
            _buildPracticeTypeCard(
              context,
              title: '常识判断',
              description: '法律、科技、文化等常识',
              icon: Icons.psychology,
              color: Colors.green,
              route: '/practice/questions/common_sense',
            ),
            const SizedBox(height: 10),
            _buildPracticeTypeCard(
              context,
              title: '言语理解与表达',
              description: '阅读理解、语言文字运用',
              icon: Icons.menu_book,
              color: Colors.orange,
              route: '/practice/questions/verbal_comprehension',
            ),
            const SizedBox(height: 10),
            _buildPracticeTypeCard(
              context,
              title: '数量关系',
              description: '数学运算、数字推理',
              icon: Icons.calculate,
              color: Colors.red,
              route: '/practice/questions/quantitative_relation',
            ),
            const SizedBox(height: 10),
            _buildPracticeTypeCard(
              context,
              title: '判断推理',
              description: '逻辑判断、图形推理',
              icon: Icons.quiz,
              color: Colors.purple,
              route: '/practice/questions/logical_reasoning',
            ),
            const SizedBox(height: 10),
            _buildPracticeTypeCard(
              context,
              title: '资料分析',
              description: '统计图表、数据分析',
              icon: Icons.analytics,
              color: Colors.teal,
              route: '/practice/questions/data_analysis',
            ),
          ],
        ),
      ),
    );
  }
  
  Widget _buildPracticeTypeCard(BuildContext context, {
    required String title,
    required IconData icon,
    required Color color,
    required String route,
    String? description,
  }) {
    // 从题目列表路由转换为直接练习路由
    String practiceRoute = route.replaceFirst('questions', 'start');
    
    return Card(
      elevation: 4,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
      child: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            Row(
              children: [
                Icon(icon, size: 40, color: color),
                const SizedBox(width: 16),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        title,
                        style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold, fontFamily: 'FangSong'),
                      ),
                      if (description != null)
                        Padding(
                          padding: const EdgeInsets.only(top: 4),
                          child: Text(
                            description,
                            style: TextStyle(fontSize: 14, color: Colors.grey[600], fontFamily: 'FangSong'),
                          ),
                        ),
                    ],
                  ),
                ),
              ],
            ),
            const SizedBox(height: 12),
            Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                // 题目管理按钮
                OutlinedButton.icon(
                  icon: const Icon(Icons.list, size: 16),
                  label: const Text('题目管理', style: TextStyle(fontFamily: 'FangSong')),
                  onPressed: () => context.go(route),
                  style: OutlinedButton.styleFrom(
                    foregroundColor: color,
                    side: BorderSide(color: color),
                    padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
                  ),
                ),
                const SizedBox(width: 8),
                // 开始练习按钮
                ElevatedButton.icon(
                  icon: const Icon(Icons.play_arrow, size: 16),
                  label: const Text('开始练习', style: TextStyle(fontFamily: 'FangSong')),
                  onPressed: () => context.go(practiceRoute),
                  style: ElevatedButton.styleFrom(
                    backgroundColor: color,
                    foregroundColor: Colors.white,
                    padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );

  }
}